<style>
  #warehouseBook-update {
    padding: 20px 25px 25px 0;
  }

  #warehouseBook-update .layui-treeSelect .ztree li a, .ztree li span {
    margin: 0 0 2px 3px !important;
  }
</style>
<div class="layui-fluid" id="warehouseBook-ask">
  <form class="layui-form" action="" lay-filter="warehouseBook-ask-form">
    <input type="hidden" name="purchasefactory">
    <input type="hidden" name="warehouseid">
    <input type="hidden" name="bookid">
    <input type="hidden" name="bookmoney">
    <input type="hidden" name="flag">
    <input type="hidden" name="status">
    <div class="layui-form-item">
      <label class="layui-form-label febs-form-item-require">图书名称：</label>
      <div class="layui-input-block">
        <input type="text" name="bookname" minlength="1" maxlength="10" lay-verify="required"
               autocomplete="off" class="layui-input" readonly>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label febs-form-item-require">图书类型：</label>
      <div class="layui-input-block">
        <input type="text" name="type" autocomplete="off" class="layui-input"
               lay-verify="required" readonly>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label febs-form-item-require">数量：</label>
      <div class="layui-input-block">
        <input type="text" name="number" autocomplete="off" class="layui-input"
               lay-verify="required|number" readonly>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label febs-form-item-require">仓库：</label>
      <div class="layui-input-block">
        <select name="houseid"
                lay-verify="required"
                xm-select-direction="down"
                xm-select="insure-housename"
                xm-select-skin="default">
        </select>
      </div>
    </div>
    <div class="layui-form-item febs-hide">
      <button class="layui-btn" lay-submit="" lay-filter="warehouseBook-ask-form-submit" id="submit"></button>
    </div>
  </form>
</div>

<script data-th-inline="javascript">
  layui.use(['febs', 'form', 'validate', 'formSelects'], function () {
    var $ = layui.$,
        febs = layui.febs,
        layer = layui.layer,
        form = layui.form,
        warehouseBook = [[${warehouseBook}]],
        formSelects = layui.formSelects,
        $view = $('#warehouseBook-ask'),
        validate = layui.validate;

    form.verify(validate);
    form.render();

    initwarehouseBookValue();

    formSelects.render();
    formSelects.config('insure-housename', {
      searchUrl: ctx + 'warehouseHouse/list',
        response: {
        statusCode: 200
      },
      beforeSuccess: function (id, url, searchVal, result) {
        var data = result.data.rows;
        var tranData = [];
        for (var i = 0; i < data.length; i++) {
          tranData.push({
            name: data[i].housename,
            value: data[i].houseid
          })
        }
        result.data = tranData;
        return result;
      },
      error: function (id, url, searchVal, err) {
        console.error(err);
        febs.alert.error('仓库加载失败');
      }
    });

    function initwarehouseBookValue() {
      form.val("warehouseBook-ask-form", {
        "bookname": warehouseBook.bookname,
        "type": warehouseBook.type,
        "warehouseid": warehouseBook.warehouseid,
        "bookid": warehouseBook.bookid,
        "bookmoney": warehouseBook.bookmoney,
        "purchasefactory": warehouseBook.purchasefactory,
        "number": warehouseBook.number,
        "flag": warehouseBook.flag,
        "status": warehouseBook.status,
      });
    }

    form.on('submit(warehouseBook-ask-form-submit)', function (data) {
      if (febs.nativeEqual(data.field, warehouseBook)) {
        febs.alert.warn('您还未选择仓库！');
        return false;
      }
      febs.post(ctx + 'warehouseBook/in/', data.field, function () {
        layer.closeAll();
        febs.alert.success(warehouseBook.bookname + '入库成功');
        $('#febs-warehouseBookNext').find('#query').click();
      });
      return false;
    });
  });
</script>